﻿using Fast.Extensions.Authentication.JwtBearer;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Logging;
using System.Net;
using System.Security.Claims;
using System.Threading.Tasks;

namespace Fast.AspNetCore.WebApi.Tests.Controllers
{
    /// <summary>
    /// 
    /// </summary>
    [ApiController]
    [Route("[controller]"), ApiExplorerSettings(GroupName = "Othor")]
    public class AuthTestController : ControllerBase
    {

        private readonly ILogger<AuthTestController> _logger;
        private readonly ITokenService _tokenService;
        /// <summary>
        /// 
        /// </summary>
        /// <param name="logger"></param>
        /// <param name="tokenService"></param>
        public AuthTestController(ILogger<AuthTestController> logger, ITokenService tokenService)
        {
            _logger = logger;
            _tokenService = tokenService;
        }

        /// <summary>
        /// 获取Token
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        [ProducesResponseType(typeof(TokenEntity), (int)HttpStatusCode.OK)]
        public async Task<IActionResult> TokenAsync()
        {
            var jwtPayload = new JwtPayload();
            jwtPayload.Add("UserId", 1);
            jwtPayload.Add(ClaimTypes.NameIdentifier, "Admin");
            var token = await _tokenService.TokenAsync(jwtPayload);
            return Ok(token);
        }
    }
}
